package com.broada.apm.service.impl;

import com.broada.apm.ajax.AuthResult;
import com.broada.apm.base.BaseService;
import com.broada.apm.entity.Authenticate;
import com.broada.apm.model.User;
import com.broada.apm.service.AuthenticationService;

public class AuthenticationServiceImpl extends BaseService implements AuthenticationService {
	@Override
	public AuthResult login(User user) {
	    AuthResult result = new AuthResult();
		try {
			Authenticate authenticate = authenticationLogic.login(user);
			if (!authenticate.getStatus()) {
				result.setFailMessage(authenticate.getMessage());
			} else {
				result.setToken(authenticate.getToken());
				result.setUser(authenticate.getUser());
			}
		} catch (Exception e) {
			result.setFailMessage(e.getMessage());
		}
		return result;
	}

	@Override
	public AuthResult logout(String token) {
		try {
			authenticationLogic.logout(token);
		} catch (Exception e) {
			AuthResult authResult = new AuthResult();
			authResult.setFailMessage(e.getMessage());
			return authResult;
		}
		return new  AuthResult();
	}

}
